package cn.itcast.user.web;

import cn.itcast.user.VO.DateFormatVo;
import cn.itcast.user.pojo.User;
import cn.itcast.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
@RestController
@RequestMapping("/user")
// @RefreshScope   value 刷新域
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private DateFormatVo dateFormatVo;

    /**
     * 路径： /user/110
     *
     * @param id 用户id
     * @return 用户
     */
    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") Long id,@RequestHeader(value = "Truth",required = false) String name) {
        System.out.println("请求头中携带的名字:"+name);
        return userService.queryById(id);
    }

    @GetMapping("now")
    public String now(){
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(dateFormatVo.getDateformat()));
    }

    @GetMapping("/getUser")
   public User getUser(String name,String address){
        User user = new User();
        user.setUsername(name);
        user.setAddress(address);
        return user;
    }
}
